<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>款式</title>
	
	<link rel="shortcut icon" href="favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
	<script src="js/jquery.min.js?v=2.1.4"></script>
<!--	"http://localhost:8081/lecture/fileupload.do"-->
	<!--文件上传js	-->
	

	</head>

<body>
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
            <div class="col-sm-6">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<h5>修改款式信息</h5>
						</div>
						<div class="ibox-content">
							<form class="form-horizontal m-t" id="commentForm" onsubmit="return uploadForm();">
								<div class="form-group">
									<label class="col-sm-3 control-label">款式名：</label>
									<div class="col-sm-8">
										<input id="stylename" name="stylename" minlength="2" type="text" class="form-control" required="" aria-required="true" readonly="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">款号：</label>
									<div class="col-sm-8">
										<input id="styleid" name="styleid" minlength="2" maxlength="15" type="text" class="form-control" required="number" aria-required="true"
											   readonly="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">颜色:</label>
									<div class="col-sm-8">
										<input id="colour" name="colour" type="color" readonly="true"/>
										<p style="color:red;">(不可修改)</p>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">规格：</label>
<!--
									<div class="col-sm-8">
										<select id="standard" class="form-control m-b" name="standard">
                                        <option value="S">S</option>
                                        <option value="M">M</option>
                                        <option value="L">L</option>
                                        <option value="XL">XL</option>
										<option value="XXL">XXL</option>
										<option value="XXXL">XXXL</option>
                                    </select>
									</div>
-->
									<div class="col-sm-8">
										<input id="standard" name="standard" minlength="1" type="text" class="form-control" required="" aria-required="true" readonly="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">号型：</label>
									<div class="col-sm-8">
										<input id="size" name="size" class="form-control" placeholder="例如：155/76A" />
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">面料：</label>
									<div class="col-sm-8">
										<input id="material" name="material" class="form-control" >
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">零售价：</label>
									<div class="col-sm-8">
										<input id="price" name="price" minlength="1" type="text" class="form-control" required="number" aria-required="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">图片：</label>
									<div class="col-sm-8">
										<input type="text" name="picture1" id="picture1"  class="form-control" >
<!--										<form id="uploadForm" enctype="multipart/form-data">-->
										<input name="file1" type="file" value="选择" size="20" id="fileUpload1" onchange ="uploadFile()"/>
											
<!--										</form>-->
										<img id="picture2" width="500" height="500"/>
									</div>
									
								</div>
								
																
								<div class="form-group">
									<div class="col-sm-4 col-sm-offset-3">
										<button class="btn btn-primary" type="submit" >提交</button>
										<button class="btn btn-primary" type="button" onclick="javascript:history.back(-1);">返回</button>
									</div>
								</div>
								
							</form>
							
							
							
						</div>
					</div>
              
            </div>
		</div>	
	</div>
	<script src="js/ajaxfileupload.js" type="text/javascript"></script>
	<script>
		//页面回显
		 $(document).ready(function (){
			 var key = window.location.href.split("?")[1].split("=")[0];
			var value = window.location.href.split("?")[1].split("=")[1];
			 if(key==="id"){
				var style={
				id: value
				}
			}else{
				var style={
				numstr:value
				}
			}
			console.log(style);
			 
			 $.ajax({
            	//几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "http://localhost:8081/lecture/selectStyleBy" ,//url
                data: JSON.stringify(style),
				contentType: "application/json;charset=UTF-8",
                success: function (rsp) {
                   	console.log(rsp);
					if(rsp.respCode==="0"){
						console.log(rsp.data);
					
						$("#stylename").val(rsp.data.stylename);
						$("#numstr").val(rsp.data.numstr);
						$("#styleid").val(rsp.data.styleid);
						$("#colour").val(rsp.data.colour);
						$("#standard").val(rsp.data.standard);
						$("#size").val(rsp.data.size);
						$("#material").val(rsp.data.material);
						$("#price").val(rsp.data.price);
						$("#operator").val(rsp.data.operator);
						$("#createtime").val(rsp.data.createtime);
//						$("#picture1").val(rsp.data.picture);
		document.getElementById("picture2").src="D:\\IdeaProjects\\store\\target\\store\\"+rsp.data.picture;
						if(rsp.data.flag=="1"){
						   	$("#flag").val("可用");
						   }else{
							 $("#flag").val("已删除");  
						   }
					}else{
						alert(rsp.respDesc);
					}
					
					
				},
				error:function(){
					 window.location.href="500.html";
				}
            });
			 
			 
		 });
		
		function uploadFile() {
// 				let form = document.getElementById('uploadForm'); //获取form表单
//
//  				let data = new FormData(form);//拿到表单创建FormData对象；
			
			var s = $('#fileUpload1')[0].files[0];
			var formData = new FormData();
        	formData.append("file", s);

				let url='http://localhost:8081/lecture/fileupload.do';

				 $.ajax({
							url: url,
							type: "POST",
							data: formData,
							contentType: false,
							processData: false,
							success: function (json) {
							//上传成功
								console.log(json);
								alert("图片上传成功");
								$("#picture1").val(json);
	document.getElementById("picture2").src="D:\\IdeaProjects\\store\\target\\store\\"+json;
							},
							error: function (data) {
							 //上传失败
								alert("图片上传失败");
							}
						});
			
		};
		
		//form 提交
		function uploadForm(){
			var id = window.location.href.split("?")[1].split("=")[1];
			var style={
				id:id,
				stylename:$("#stylename").val(),
				styleid:$("#styleid").val(),
				colour:$("#colour").val(),
				standard:$("#standard").val(),
				size:$("#size").val(),
				material:$("#material").val(),
				price:$("#price").val(),
				picture:$("#picture1").val()
			};
			console.log(style);
			$.ajax({
            //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "http://localhost:8081/lecture/updateStyle" ,//url
                data: JSON.stringify(style),
				contentType: "application/json;charset=UTF-8",
                success: function (rsp) {
                   	console.log(rsp);
					if(rsp.respCode==="0"){
						alert("修改成功");
						window.location.href="tableKS.html";
						
					}else{
						alert(rsp.respDesc);
						
					}
					
					
				},
				error:function(){
					 window.location.href="500.html";
					
				}
            });
			return false;
		}
	</script>
</body>
</html>
